<template>
  <div class="user_main">
    <el-card class="card" shadow="never">
      <div slot="header">
        注册用户列表
      </div>
      <el-table
        v-loading="loading"
        :data="userList"
        border
        style="width: 100%"
      >
        <el-table-column type="index" label="序号" fixed="left" />
        <el-table-column
          align="center"
          prop="username"
          label="用户名"
          width="200"
        />
        <el-table-column
          align="center"
          prop="username"
          label="头像"
          width="200"
        >
          <template slot-scope="scope">
            <el-avatar style="width:60px;height:60px" size="small" :src="scope.row.icon" />
          </template>
        </el-table-column>
        <el-table-column
          align="center"
          prop="nickname"
          label="昵称"
          width="150"
        />
        <el-table-column
          align="center"
          prop="realname"
          label="真实姓名"
          width="200"
        />
        <el-table-column
          align="center"
          prop="sex"
          label="性别"
          width="200"
        />
        <el-table-column
          align="center"
          prop="phone"
          label="电话"
          width="200"
        />
        <el-table-column
          align="center"
          prop="email"
          label="邮箱"
          width="200"
        />
        <el-table-column
          align="center"
          prop="birthday"
          label="生日"
          width="200"
        />
        <el-table-column
          align="center"
          prop="createTime"
          label="注册时间"
        />
        <!-- <el-table-column fixed="right" label="操作" width="100">
          <template slot-scope="scope">
            <el-button
              type="text"
              size="small"
              @click="goEdit(scope.row)"
            >编辑</el-button>
            <el-button
              type="text"
              size="small"
              @click="goDelete(scope.row)"
            ><span style="color: red">删除</span></el-button>
          </template>
        </el-table-column> -->

      </el-table>

      <el-pagination
        :current-page="page.currentPage"
        :page-sizes="page.pageSizes"
        :page-size="page.size"
        layout="total, sizes, prev, pager, next, jumper"
        :total="page.total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </el-card>
  </div>
</template>

<script>
import userApi from '@/api/user/index'
import mixin from '@/mixins/index'
export default {
    name: 'UserList',
    mixins: [mixin],
    data() {
        return {
            userList: [],
            loading: false
        }
    },
    created() {
        this.getUserList()
    },
    methods: {
        getUserList() {
            this.loading = true
            userApi.getUserList(this.page.currentPage, this.page.size).then(res => {
                if (res.success) {
                    this.userList = res.data.rows
                    // console.log(JSON.stringify(res.data.rows))
                    this.page.total = res.data.total
                }
                this.loading = false
            })
        },
        //   分页size改变
        handleSizeChange(val) {
            this.page.size = val
            this.page.currentPage = 1
            this.getUserList()
        },
        handleCurrentChange(val) {
            this.page.currentPage = val
            this.getUserList()
        }
    }
}
</script>

<style lang="scss" scoped>
.user_main {
  .card {
    margin: 30px;
  }

   .table_img {
    width: 100px;
    height: 100px;
  }
}
</style>
